package main

import (
    "os"
    "os/signal"
    "fmt"
    "rpcserver/server"
    "math/rand"
    "strconv"
    "time"
)

func main() {
    if len(os.Args) < 2 {
        fmt.Printf("invalid args : %s server_id\n", os.Args[0])
        return
    }

    id, err := strconv.Atoi(os.Args[1])
    if err != nil {
        fmt.Fprintf(os.Stderr, "start convert %s\n", err)
        return
    }

    rand.Seed(time.Now().UnixNano())
    server := server.NewServer(id)
    go server.Start()

    c := make(chan os.Signal, 1)
    signal.Notify(c, os.Interrupt, os.Kill)
    sig := <-c
    fmt.Printf("server closing down (signal: %v)", sig)
}
